#pragma once

#include "MBPlane.h"

/**
  * MBCameraViewFrustum of a perspective camera defined by six planes
  */
class MBCameraViewFrustum
{
public:
	MBCameraViewFrustum( void );
	~MBCameraViewFrustum( void );

	void SetCamInternals( const double &angle, const double &ratio, const double &nearD, const double &farD );
	void SetCamDef( const MBVec3 &position, const MBVec3 &lookAtPoint, const MBVec3 &upVector );
	bool IsAxisAlignedBoxIntersectingFrustum( const MBVec3 &boxMin, const MBVec3 &boxMax ) const;

	/** Number of planes of the camera view frustum */
	static const MBuint MB_CAMERA_VIEW_FRUSTUM_NUM_PLANES = 6u;

private:
	/** Index indicating which plane is meant */
	enum {
		TOP = 0,
		BOTTOM,
		LEFT,
		RIGHT,
		NEARP,
		FARP
	};
	/** Array of pointers to the six planes defining the view frustum */
	MBPlane mPlanes[MB_CAMERA_VIEW_FRUSTUM_NUM_PLANES];
	/** Distance to the near clipping plane */
	double mNearD;
	/** Distance to the far clipping plane */
	double mFarD;
	/** Aspect ratio of the clipping planes, width / height */
	double mRatio;
	/** Vertical aperture angle of the view-frustum */
	double mAngle;
	/** Tangent of the half angle */
	double mTang;
	/** Half width of the near clipping plane */
	double mNw;
	/** Half height of the near clipping plane */
	double mNh;
	/** Half width of the far clipping plane */
	double mFw;
	/** Half height of the far clipping plane */
	double mFh;
};